using System.Reflection;
using System.Text;
using System.Text.Json;
using RkCalendar.ViewModel;

namespace RkCalendar
{
    public static class TimeHelper
    {
        private static Dictionary<DayOfWeek, string> dayOfWeekStrDict = new Dictionary<DayOfWeek, string>
        {
            {DayOfWeek.Monday,      "一"},
            {DayOfWeek.Tuesday,     "二"},
            {DayOfWeek.Wednesday,   "三"},
            {DayOfWeek.Thursday,    "四"},
            {DayOfWeek.Friday,      "五"},
            {DayOfWeek.Saturday,    "六"},
            {DayOfWeek.Sunday,      "日"},
        };

        private static Dictionary<char, string> zodiacDict = new Dictionary<char, string>
        {
            {'子' , "鼠🐀"},
            {'丑' , "牛🐂"},
            {'寅' , "虎🐅"},
            {'卯' , "兔🐇"},
            {'辰' , "龙🐉"},
            {'巳' , "蛇🐍"},
            {'午' , "马🐎"},
            {'未' , "羊🐏"},
            {'申' , "猴🐒"},
            {'酉' , "鸡🐓"},
            {'戌' , "狗🐕"},
            {'亥' , "猪🐖"}
        };

        public static string GetDayOfWeekStr(DayOfWeek dayOfWeek)
        {
            return dayOfWeekStrDict[dayOfWeek];
        }

        public static string GetYearOf12ZodiacSigns(string gzYear)
        {
            char zhiStr = gzYear.Length >=2 ? gzYear[1] : ' ';
            return zodiacDict.ContainsKey(zhiStr) ? zodiacDict[zhiStr] : string.Empty;
        }

        public static List<AlmanacData> GetAlmanacDatas(int year)
        {
            if (year < 2024 || year > 2030)
                return new List<AlmanacData>();

            string fileName = $"Calendar.Resources.{year}tcCalendar.json";
            string jsonStr = string.Empty;
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fileName))
            {
                if (stream != null)
                {
                    var reader = new StreamReader(stream, Encoding.UTF8, true);
                    jsonStr = reader.ReadToEnd();
                }
            }

            var almanacDatas = JsonSerializer.Deserialize<List<AlmanacData>>(jsonStr);
            if (almanacDatas != null)
                return almanacDatas;
            else
                return new List<AlmanacData>();

        }
    }
}

